package com.twu.biblioteca;

import java.util.Scanner;

/**
 * Created by theyes on 15/01/2014.
 */
public class UserInputHandler {


    private Scanner ioScanner = new Scanner(System.in);

    public String readInput() {

        String input = ioScanner.nextLine();
        return input;
    }

    public String readInputNoWhiteSpcace() {

        String input = "";
        while(input.isEmpty() || input.length() <1 || input.equals(""))
        {
            input = ioScanner.nextLine();
            input = input.trim();
            input = input.replaceAll("\\s+","");
        }

        return input;
    }

    public int readInputInt() {
        String input = readInputNoWhiteSpcace();

        while(!determineInt(input))
        {
            input = readInputNoWhiteSpcace();
        }

        int int_input = Integer.parseInt(input);
        return int_input;
    }

    public boolean determineInt(String input)
    {
        char working_char ;

        for(int i = 0; i < input.length(); i++)
        {
            working_char = input.charAt(i);
            if(!Character.isDigit(working_char))
            {
                System.out.println("Invalid input please enter a number");
                return false;
            }
        }
        return true;

    }
}
